<?php
defined( 'BASEPATH' ) or exit( 'No direct script access allowed' );
class Links_model extends MY_Model
{
    function get($gid, $max = 10)
    {
        $this->_db->select( $this->_table, '`id`,`sub_id`,`target`,`uri`,`selected_uri`,`img_cover`,`title`,`subtitle`,`description`,`ext`' );
        $this->_db->where( '`gid`=? and `enable`=1 and `deleted`=0', $gid );
        $this->_db->order( '`sort` desc,`id`' );
        $this->_db->limit( $max );
        if ($rows = $this->_db->fetch_all())
        {
            foreach ( $rows as &$item )
            {
                if (substr( $item['uri'], 0, 7 ) === 'http://' || substr( $item['uri'], 0, 8 ) === 'https://')
                {
                    continue;
                }
                if ($item['uri'] == '#')
                {
                    $item['uri'] = '';
                }
                $item['uri'] = site_url( $item['uri'] );
            }
            return $rows;
        }
        return array ();
    }
}